home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
UPC12BS2.ZIP
/
UTIL
/
GENSIG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-27
|
22KB
|
575 lines
/*--------------------------------------------------------------------*/
/* Program: gensig.c 24 July 1991 */
/* Author: Andrew H. Derbyshire */
/* Address: ahd@kew.com */
/* Function: Append a random quote to an electronic */
/* mail signature file */
/* Language: Borland C++ 2.0 (in ANSI C mode) */
/* Arguments: Name of file with fixed text input */
/* Name of file with variable quotes */
/* Name of file to be written */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: gensig.c 1.4 1993/09/27 04:04:06 ahd Exp $
*
* Revision history:
* $Log: gensig.c $
* Revision 1.4 1993/09/27 04:04:06 ahd
* Suppress compiler warning message
*
* Revision 1.3 1993/04/11 00:33:54 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.2 1993/03/06 23:04:54 ahd
* Alter message to include output files
*
* Revision 1.1 1992/11/15 04:29:22 ahd
* Initial revision
*
*/
static char rcsid[] = "$Id: gensig.c 1.4 1993/09/27 04:04:06 ahd Exp $";
/*--------------------------------------------------------------------*/
/* Standard include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <direct.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "timestmp.h"
/*--------------------------------------------------------------------*/
/* Local macros */
/*--------------------------------------------------------------------*/
#define bitsper(s) (8 * (sizeof s))
#define bitflag(x, s) (1 << ((bitsper(s) - 1) - x))
#define biton( s, offset ) \
(( s[ (size_t) (offset / bitsper(*s)) ] ) & \
bitflag(offset % bitsper( *s ), *s))
#define bitoff( s, offset) (!biton(s, offset))
/*--------------------------------------------------------------------*/
/* Internal function prototypes */
/*--------------------------------------------------------------------*/
static void usage( void );
static long chooseit( struct stat *current_status,
const char *lookaside,
const char *quoteused,
const char *fname ,
const char *target);
static long getquote( const char *data, const char *target);
static void CopyQuote( const char *fname, long where, FILE *stream);
static void CopyFixed( const char *fname, FILE *stream );
static long chooseavailable( const char *quoteused, long quotes );
currentfile();
/*--------------------------------------------------------------------*/
/* m a i n */
/* */
/* main program */
/*--------------------------------------------------------------------*/
void main( int argc, char **argv)
{
long where;
FILE *stream;
banner( argv );
/*--------------------------------------------------------------------*/
/* Validate the number of arguments */
/*--------------------------------------------------------------------*/
if ( argc != 4 )
usage();
/*--------------------------------------------------------------------*/
/* Determine the number of the quotes available, and then */
/* select one */
/*--------------------------------------------------------------------*/
where = getquote( argv[2], argv[3] );
/*--------------------------------------------------------------------*/
/* Open up our output file */
/*--------------------------------------------------------------------*/
stream = fopen( argv[3] , "w");
if ( stream == NULL )
{
perror( argv[3] );
exit(1);
}
/*--------------------------------------------------------------------*/
/* Copy the fixed and variable parts of the file */
/*--------------------------------------------------------------------*/
CopyFixed( argv[1], stream );
CopyQuote( argv[2], where, stream );
/*--------------------------------------------------------------------*/
/* Close up and return to caller */
/*--------------------------------------------------------------------*/
fclose( stream );
exit( 0 );
} /* main */
/*--------------------------------------------------------------------*/
/* u s a g e */
/* */
/* Report program usage and then exit */
/*--------------------------------------------------------------------*/
static void usage( void )
{
printf("Usage:\tgensig\taddr-file quote-file output-file\n");
printf("\taddr-file\tFixed portion of signature file\n");
printf("\tquote-file\tFile of quotes, separated by delimiter lines\n");
printf("\toutput-file\tOutput file with fixed portion and single quote\n");
exit( 2 );
} /* usage */
/*--------------------------------------------------------------------*/
/* g e t q u o t e */
/* */
/* Select a quote to process */
/*--------------------------------------------------------------------*/
static long getquote( const char *data, const char *target)
{
struct stat current_status;
long where;
char lookaside[FILENAME_MAX];
char quoteused[FILENAME_MAX];
char drive[FILENAME_MAX],
dir[FILENAME_MAX],
file[FILENAME_MAX],
ext[FILENAME_MAX];
/*--------------------------------------------------------------------*/
/* Get size and data information on the quotes data file */
/*--------------------------------------------------------------------*/
if(stat((char *) data, ¤t_status ) <0)
{
perror( data ); /* If no data file, panic gracefully */
exit( 3 );
} /* if */
/*--------------------------------------------------------------------*/
/* Build the lookaside file name from the data file name */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
fnsplit( data, drive, dir, file, ext);
fnmerge( lookaside, drive, dir, file, ".las");
fnmerge( quoteused, drive, dir, file, ".qus");
#else
_splitpath( data, drive, dir, file, ext);
_makepath( lookaside, drive, dir, file, ".las");
_makepath( quoteused, drive, dir, file, ".qus");
#endif /* __TURBOC__ */
/*--------------------------------------------------------------------*/
/* Now get the location of the quote; if it fails the first */
/* time, then the lookaside buffer is updated and we can try */
/* again */
/*------------------------